package com.chinags.system.expert.controller;

import com.chinags.common.annotation.Log;
import com.chinags.common.core.controller.BaseController;
import com.chinags.common.core.domain.AjaxResult;
import com.chinags.common.core.domain.Ztree;
import com.chinags.common.core.page.TableDataInfo;
import com.chinags.common.enums.BusinessType;
import com.chinags.common.utils.poi.ExcelUtil;
import com.chinags.framework.util.ShiroUtils;
import com.chinags.system.expert.domain.TJcExpertInfo;
import com.chinags.system.expert.service.ITJcExpertInfoService;
import com.chinags.system.tJcJcjgJcyq.domain.TJcJcjgJcyq;
import com.chinags.system.testingfacility.domain.TJcJcjgCyry;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 专家 信息操作处理
 * 
 * @date 2019-06-20
 */
@Controller
@RequestMapping("/system/tJcExpertInfo")
public class TJcExpertInfoController extends BaseController
{
    private String prefix = "system/tJcExpertInfo";
	
	@Autowired
	private ITJcExpertInfoService tJcExpertInfoService;

	@RequiresPermissions("system:tJcExpertInfo:view")
	@GetMapping()
	public String tJcExpertInfo()
	{
	    return prefix + "/tJcExpertInfo";
	}
	
	/**
	 * 查询专家列表
	 */
	@RequiresPermissions("system:tJcExpertInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TJcExpertInfo tJcExpertInfo)
	{
		startPage();
        List<TJcExpertInfo> list = tJcExpertInfoService.selectTJcExpertInfoList(tJcExpertInfo);
		return getDataTable(list);
	}

	
	/**
	 * 导出专家列表
	 */
	@RequiresPermissions("system:tJcExpertInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TJcExpertInfo tJcExpertInfo)
    {
    	List<TJcExpertInfo> list = tJcExpertInfoService.selectTJcExpertInfoList(tJcExpertInfo);
        ExcelUtil<TJcExpertInfo> util = new ExcelUtil<TJcExpertInfo>(TJcExpertInfo.class);
        return util.exportExcel(list, "tJcExpertInfo");
    }
	
	/**
	 * 新增专家
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存专家
	 */
	@RequiresPermissions("system:tJcExpertInfo:add")
	@Log(title = "专家", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TJcExpertInfo tJcExpertInfo)
	{		
		return toAjax(tJcExpertInfoService.insertTJcExpertInfo(tJcExpertInfo));
	}

	/**
	 * 修改专家
	 */
	@GetMapping("/edit/{expertInfoId}")
	public String edit(@PathVariable("expertInfoId") Long expertInfoId, ModelMap mmap)
	{
		TJcExpertInfo tJcExpertInfo = tJcExpertInfoService.selectTJcExpertInfoById(expertInfoId);
		mmap.put("tJcExpertInfo", tJcExpertInfo);
	    return prefix + "/edit";
	}

	/**
	 * 专家详情
	 */
	@GetMapping("/detail/{expertInfoId}")
	public String detail(@PathVariable("expertInfoId") Long expertInfoId, ModelMap mmap)
	{
		TJcExpertInfo tJcExpertInfo = tJcExpertInfoService.selectTJcExpertInfoById(expertInfoId);
		mmap.put("tJcExpertInfo", tJcExpertInfo);
	    return prefix + "/detail";
	}

	/**
	 * 修改保存专家
	 */
	@RequiresPermissions("system:tJcExpertInfo:edit")
	@Log(title = "专家", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TJcExpertInfo tJcExpertInfo)
	{		
		return toAjax(tJcExpertInfoService.updateTJcExpertInfo(tJcExpertInfo));
	}
	
	/**
	 * 删除专家
	 */
	@RequiresPermissions("system:tJcExpertInfo:remove")
	@Log(title = "专家", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tJcExpertInfoService.deleteTJcExpertInfoByIds(ids));
	}

	/**
	 * 下载模板
	 */
	@GetMapping("/importTemplate")
	@ResponseBody
	public AjaxResult importTemplate()
	{
		ExcelUtil<TJcJcjgJcyq> util = new ExcelUtil<TJcJcjgJcyq>(TJcJcjgJcyq.class);
		return util.importTemplateExcel("检测机构仪器设备数据");
	}

	/**
	 * 导入数据
	 */
	@PostMapping("/importData")
	@ResponseBody
	public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
	{
		ExcelUtil<TJcExpertInfo> util = new ExcelUtil<TJcExpertInfo>(TJcExpertInfo.class);
		List<TJcExpertInfo> expertList = util.importExcel(file.getInputStream());//将Excel转换成BO的List
		String operName = ShiroUtils.getSysUser().getLoginName();//当前登录用户名
		String message = tJcExpertInfoService.importData(expertList,updateSupport,operName);
		return AjaxResult.success(message);
	}
}
